<%
  # Temporary solution until refinerycms supporst html attributes for menu links
  if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
    if menu_branch.html
      if menu_branch.html[:class]
        menu_branch.html[:class] += ' ' + classes.join(' ')
      else
        menu_branch.html[:class] = classes.join(' ')
      end
    else
      menu_branch.html = {:class => classes.join(' ')}
    end
  end

  if Refinery::Menus.html_attributes
    css = ''
    menu_branch.html.each do |attr, value|
      css += "#{attr}='#{value}' ".html_safe
    end
  else
    css = "class='#{classes.join(' ')}'".html_safe
  end

-%>
<li<%= ['', css].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
<%= link_to(menu_branch.title, refinery.url_for(menu_branch.url)) -%>
  <% if ( (children = menu_branch.children unless hide_children).present? &&
          (!local_assigns[:menu_levels] || menu_branch.ancestors.length < local_assigns[:menu_levels]) ) -%>
    <ul class='clearfix'>
      <%= render :partial => '/refinery/menu_branch', :collection => children,
                 :locals => {
                   :apply_css => local_assigns[:apply_css],
                   :hide_children => !!hide_children,
                   :menu_levels => local_assigns[:menu_levels]
                 } -%>
    </ul>
  <% end -%>
</li>
